package com.example.test.utils;

import com.example.test.constants.SystemConstant;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * @author ：dengjue
 * @date ：Created in 2021/11/27 12:11
 * @description ：
 */
public class TokenUtil {

    public static String generateToken(){
        return UUID.randomUUID().toString();
    }

    public static String getToken(HttpServletRequest request){
        String token = request.getHeader(SystemConstant.TOKEN_NAME);
        if (StringUtils.isEmpty(token)){
            token = request.getParameter(SystemConstant.TOKEN_NAME);
        }
        return token;
    }
}
